//
//  WmcHomeLockActionView.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/8/18.
//

import UIKit

extension WmcHomeLockActionView {
    struct Ignore {
        /// 忽略的视图
        var view: UIView
        /// 这个视图所属平台
        /// 用于一个视图忽略表现在不同平台
        var platforms: [YPWmcManager.Platform]
        
        /// 是否为反选
        /// platforms即为非该平台下的其他平台
        var isreverseSelect: Bool = false
    }
}

class WmcHomeLockActionView: WmcBaseView {
    /// 需要忽略点击事件的区域
    var ignores: [Ignore] = []

    /// 重写
    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        let supView = super.hitTest(point, with: event)
        let currentPlatform =  YPWmcManager.shared.platform
        
        for ignore in ignores {
            var isContains = ignore.platforms.contains(currentPlatform)
            if ignore.isreverseSelect {
                isContains = !isContains
            }
            if isContains {
                let ignoreView = ignore.view
                let frame = ignoreView.convert(ignoreView.bounds, to: self)
                if frame.contains(point) {
                    return nil
                }
            }
        }
        return supView
    }
    
    override func makeUI() {
        backgroundColor = .clear
    }
}
